package com.example.zzm.yuejian03.Fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zzm.yuejian03.R;
import static android.content.Context.MODE_PRIVATE;

public abstract class BaseFragment extends Fragment {
    protected int layout_file= R.layout.fragment_home;
    View view=null;
    private String id;
    abstract  void initView();
    abstract  void initEvent();   //点击事件
    abstract  void initData();    //数据

    public int getLayout_file() {
        return layout_file;
    }

    public void setLayout_file(int layout_file) {
        this.layout_file = layout_file;
    }
    public BaseFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view=inflater.inflate(getLayout_file(),container,false);//false,不是真的包括在类里，只是做布局解析
        initView();
        initEvent();
        initData();
        return view;
    }
    public String getUser_name(){
        SharedPreferences sp;
        sp=getActivity().getSharedPreferences("userInfo",MODE_PRIVATE);
        return  sp.getString("name","");
    }

    public String getUser_password(){
        SharedPreferences sp;
        sp=getActivity().getSharedPreferences("userInfo", MODE_PRIVATE);
        return  sp.getString("password","");
    }
    public int getUser_id(){
        SharedPreferences sp;
        sp=getContext().getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        return  sp.getInt("user_id",1);
    }
}

